<script setup name="AccountSelect" lang="ts">

import { AccountVO, listAccount } from '@/views/fms/account/api';

// 声明外部传入的数据
const props = defineProps({
  accountId: {type: Number, default: ''},
  params: {type: Object, default: undefined}
});
const pd = reactive({
  accountList: <AccountVO[]>([]),
  queryParams: <AccountVO>{
    parentId: -1,
    name: ''
  }
});

/** 查询测试树列表 */
async function getList() {
  pd.queryParams = {...pd.queryParams, ...props.params};
  const res = await listAccount(pd.queryParams);
  pd.accountList = res.data;
}
// 定义需要回传的数据
const emits = defineEmits(["update:accountId"]);

const {proxy} = getCurrentInstance() as ComponentInternalInstance

const accountId = computed({
  get() {
    return props.accountId
  },
  set(val) {
    emits("update:accountId", val)
  }
})

onMounted(() => {
  getList();
});
</script>

<template>
  <el-select v-model="accountId" clearable>
    <el-option v-for="item in pd.accountList" :key="item.id" :label="item.name" :value="item.id"/>
  </el-select>
</template>
